package com.java.util;

import com.zhenzi.sms.ZhenziSmsClient;

import java.util.HashMap;
import java.util.Map;


public class SMSUtil {

    /**
     * 后台管理录入手机获取短信
     * @param phoneNumber
     * @param code
     */
    public static void sendSMS(String phoneNumber, String code){
        String apiUrl = "https://sms_developer.zhenzikj.com";
        String appId = "102102";
        String appSecret = "5eddd0a2-9ebe-43a9-a8ca-61ab0d64c139";
        ZhenziSmsClient client = new ZhenziSmsClient(apiUrl, appId, appSecret);
        Map<String, Object> params = new HashMap<String, Object>();
        params.put("number", phoneNumber);
        params.put("templateId", "4126");
        String[] templateParams = new String[1];
        templateParams[0] = code;
        params.put("templateParams",templateParams);
        try {
            String result = client.send(params);
            String balance = client.balance();
            System.out.println(result);
            System.out.println(balance);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    /**
     * 微信端用户登录获取短信验证
     * @param phoneNumber
     * @param code
     * @return
     */
    public static boolean loginSMS(String phoneNumber, String code){
        String apiUrl = "https://sms_developer.zhenzikj.com";
        String appId = "102102";
        String appSecret = "5eddd0a2-9ebe-43a9-a8ca-61ab0d64c139";
        ZhenziSmsClient client = new ZhenziSmsClient(apiUrl, appId, appSecret);
        Map<String, Object> params = new HashMap<String, Object>();
        params.put("number", phoneNumber);
        params.put("templateId", "4097");
        String[] templateParams = new String[1];
        templateParams[0] = code;
        params.put("templateParams",templateParams);
        try {
            String result = client.send(params);
            String balance = client.balance();
            System.out.println(result);
            System.out.println(balance);
            return true;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return false;
    }

}
